import re

# 给定的文本
text = """
TCP    0.0.0.0:7999           0.0.0.0:0              LISTENING       7320
TCP    127.0.0.1:7999         127.0.0.1:60570        ESTABLISHED     7320
TCP    127.0.0.1:7999         127.0.0.1:60572        ESTABLISHED     7320
TCP    127.0.0.1:60570        127.0.0.1:7999         ESTABLISHED     4536
TCP    127.0.0.1:60572        127.0.0.1:7999         ESTABLISHED     4536
TCP    [::]:7999              [::]:0                 LISTENING       7320
"""

# 定义正则表达式模式
pattern = r'LISTENING\s+(\d+)'

# 使用re.search查找匹配的PID
match = re.search(pattern, text)

if match:
    pid = match.group(1)
    print(f"Listening PID: {pid}")
else:
    print("No matching LISTENING state found.")
